// 类型别名
type fnType = (x: number, y: number) => number
function sum(x: number, y: number): number {
  return x + y
}
const sum2: fnType = sum

// 类型断言
function getLen(input: string|number): number {
  // 写法1
  // const str = input as String
  // if (str.length) {
  //   return str.length
  // } else {
  //   const number = input as Number
  //   return number.toString().length
  // }
  // 写法2
  if((<string>input).length) {
    return (<string>input).length
  } else {
    return input.toString().length
  }
}